package com.csy.commons.core.exception;


import com.csy.commons.core.domain.BaseResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BaseException.class)
    @ResponseBody
    public BaseResponse baseExceptionHander(BaseException e){
        return BaseResponse.fail(e.getDefaultMessage());
    }

    /**
     *业务异常处理器
     */
    @ExceptionHandler(CustomException.class)
    public BaseResponse businessException(CustomException e){

        return BaseResponse.fail(e.getCode()+"",e.getMsg(),e.isSuccess());
    }
}
